<!--$Id: stdmode.so,v 10.27 2007/10/26 15:02:17 bostic Exp $-->
<!--Copyright (c) 1997,2008 Oracle.  All rights reserved.-->
<!--See the file LICENSE for redistribution information.-->
<html>
<head>
<title>Berkeley DB Reference Guide: Standard lock modes</title>
<meta name="description" content="Berkeley DB: An embedded database programmatic toolkit.">
<meta name="keywords" content="embedded,database,programmatic,toolkit,btree,hash,hashing,transaction,transactions,locking,logging,access method,access methods,Java,C,C++">
</head>
<body bgcolor=white>
<a name="2"><!--meow--></a>
<table width="100%"><tr valign=top>
<td><b><dl><dt>Berkeley DB Reference Guide:<dd>Locking Subsystem</dl></b></td>
<td align=right><a href="../lock/max.html"><img src="../../images/prev.gif" alt="Prev"></a><a href="../toc.html"><img src="../../images/ref.gif" alt="Ref"></a><a href="../lock/dead.html"><img src="../../images/next.gif" alt="Next"></a>
</td></tr></table>
<p align=center><b>Standard lock modes</b></p>
<p>The Berkeley DB locking protocol is described by a conflict matrix.  A
conflict matrix is an NxN array in which N is the number of different
lock modes supported, and the (i, j)th entry of the array indicates
whether a lock of mode i conflicts with a lock of mode j.  In addition,
Berkeley DB defines the type <b>db_lockmode_t</b>, which is the type of a
lock mode within a conflict matrix.</p>
<p>The following is an example of a conflict matrix.  The actual conflict
matrix used by Berkeley DB to support the underlying access methods is more
complicated, but this matrix shows the lock mode relationships available
to applications using the Berkeley DB Locking subsystem interfaces directly.</p>
<br>
<b>DB_LOCK_NG</b><ul compact><li>not granted (always 0)</ul>
<b>DB_LOCK_READ</b><ul compact><li>read (shared)</ul>
<b>DB_LOCK_WRITE</b><ul compact><li>write (exclusive)</ul>
<b>DB_LOCK_IWRITE</b><ul compact><li>intention to write (shared)</ul>
<b>DB_LOCK_IREAD</b><ul compact><li>intention to read (shared)</ul>
<b>DB_LOCK_IWR</b><ul compact><li>intention to read and write (shared)</ul>
<br>
<p>In a conflict matrix, the rows indicate the lock that is held, and the
columns indicate the lock that is requested.  A 1 represents a conflict
(that is, do not grant the lock if the indicated lock is held), and a
0 indicates that it is OK to grant the lock.</p>
<blockquote><pre>		Notheld	Read    Write	IWrite	IRead	IRW
Notheld		0	0	0	0	0	0
Read*		0	0	1	1	0	1
Write**		0	1	1	1	1	1
Intent Write	0	1	1	0	0	0
Intent Read	0	0	1	0	0	0
Intent RW	0	1	1	0	0	0</pre></blockquote>
<br>
<b>*</b><ul compact><li>In this case, suppose that there is a read lock held on an object.  A new
request for a read lock would be granted, but a request for a write lock
would not.</ul>
<b>**</b><ul compact><li>In this case, suppose that there is a write lock held on an object.  A
new request for either a read or write lock would be denied.</ul>
<br>
<table width="100%"><tr><td><br></td><td align=right><a href="../lock/max.html"><img src="../../images/prev.gif" alt="Prev"></a><a href="../toc.html"><img src="../../images/ref.gif" alt="Ref"></a><a href="../lock/dead.html"><img src="../../images/next.gif" alt="Next"></a>
</td></tr></table>
<p><font size=1>Copyright (c) 1996,2008 Oracle.  All rights reserved.</font>
</body>
</html>
